package com.hnichr.ump.ping.controller;


import com.hnichr.ump.common.assessment.entity.Activity;
import com.hnichr.ump.common.ping.service.SmsSendService;
import com.hnichr.ump.common.ping.vo.SendResultVo;
import com.hnichr.ump.common.ping.vo.SmsSendVo;
import com.mxpioframework.common.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ping")
@Tag(name = "PingController", description = "消息发送接口")
public class PingController {

    @Autowired
    private SmsSendService smsSendService;

    @PostMapping("sms/v1/groupSend")
    @Operation(summary = "群发短信", description = "群发短信", method = "POST")
    public Result<SendResultVo> groupSend(@RequestBody SmsSendVo smsSendVo) {
        SendResultVo sendResultVo = smsSendService.groupSend(smsSendVo);
        if(sendResultVo==null){
            return Result.error("发送失败");
        }
        else if(sendResultVo.isSuccess()){
            return Result.OK();
        }
        else{
            return Result.error(sendResultVo.getMsg());
        }
    }

    @PostMapping("sms/v1/sendImport")
    @Operation(summary = "发送短信", description = "发送短信", method = "POST")
    public Result<SendResultVo> sendImport() {
        String msg = smsSendService.sendFromImport();
        if(StringUtils.isNotBlank(msg)){
            return Result.error(msg);
        }
        return Result.OK();
    }
}
